package com.ljx.controller;

import com.ljx.common.ResponseResult;
import com.ljx.domain.dto.AddArticleDto;
import com.ljx.domain.entity.Article;
import com.ljx.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.parameters.P;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 李捷禧
 * Date: 2023/4/21
 * ClassName: ArticleController
 */

@RestController
@RequestMapping("/content/article")
public class ArticleController {

    @Autowired
    private ArticleService articleService;

    @PostMapping
    public ResponseResult add(@RequestBody AddArticleDto article){
        return articleService.add(article);
    }

    @GetMapping("/list")
    public ResponseResult ArticleList(Integer pageNum, Integer pageSize,String title,String summary){
        return articleService.articleAll(pageNum,pageSize,title,summary);
    }

    @GetMapping("{id}")
    public ResponseResult ArtGetById(@PathVariable Long id){
        Article article = articleService.getById(id);
        return ResponseResult.okResult(article);
    }

    @PutMapping
    public ResponseResult updateArt(@RequestBody Article article){
        articleService.updateById(article);
        return ResponseResult.okResult("修改完成");
    }

    @DeleteMapping("/{id}")
    public ResponseResult deleteArt(@PathVariable List<Long> id){
        articleService.removeByIds(id);
        return ResponseResult.okResult("删除成功");
    }


}
